/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * javaanalyzerUI.java
 *
 * Created on 2009-10-30, 21:11:27
 */


package javaanalyzer;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Shape;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.geom.Point2D;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.ListSelectionEvent;

import org.apache.commons.collections15.Predicate;
import org.apache.commons.collections15.Transformer;

import edu.uci.ics.jung.algorithms.layout.FRLayout;
import edu.uci.ics.jung.algorithms.layout.Layout;
import edu.uci.ics.jung.graph.Graph;
import edu.uci.ics.jung.graph.util.Pair;
import edu.uci.ics.jung.graph.util.TestGraphs;
import edu.uci.ics.jung.visualization.DefaultVisualizationModel;
import edu.uci.ics.jung.visualization.GraphZoomScrollPane;
import edu.uci.ics.jung.visualization.VisualizationModel;
import edu.uci.ics.jung.visualization.VisualizationViewer;
import edu.uci.ics.jung.visualization.control.CrossoverScalingControl;
import edu.uci.ics.jung.visualization.control.DefaultModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ModalGraphMouse;
import edu.uci.ics.jung.visualization.control.ScalingControl;
import edu.uci.ics.jung.visualization.decorators.EllipseVertexShapeTransformer;
import edu.uci.ics.jung.visualization.decorators.ToStringLabeller;
import edu.uci.ics.jung.visualization.subLayout.GraphCollapser;
import edu.uci.ics.jung.visualization.util.PredicatedParallelEdgeIndexFunction;
import edu.uci.ics.jung.graph.SparseGraph;
import edu.uci.ics.jung.algorithms.layout.util.Relaxer;
import edu.uci.ics.jung.algorithms.layout.util.VisRunner;
import edu.uci.ics.jung.algorithms.util.IterativeContext;
import edu.uci.ics.jung.algorithms.layout.StaticLayout;
import edu.uci.ics.jung.visualization.util.Animator;
import edu.uci.ics.jung.visualization.layout.LayoutTransition;


import java.awt.Color;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.JScrollPane;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ScrollPaneLayout;
import javax.swing.border.LineBorder;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import java.awt.FlowLayout;

import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.JXTaskPane;
import org.jdesktop.swingx.JXTaskPaneContainer;

import javax.swing.filechooser.*;
import javax.swing.SwingUtilities;
import java.awt.*;
import java.awt.event.*;
import javax.swing.JFileChooser;

import javax.swing.DefaultListModel;
import javax.swing.ListModel;

import java.util.Vector;

import uml.Main;
import uml.mPackage;
import uml.mClass;
import uml.mMethod;
import uml.mTypes;
import uml.mArguments;

import jar.JarFile;
import java.io.IOException;

import przeplywy.Flow;

import javax.swing.JOptionPane;


import przeplywy.Flow;


/**
 *
 * @author Michal
 */
public class javaanalyzerUI extends javax.swing.JFrame {


    private javax.swing.JTree klasaDrzewo;
    private JScrollPane drzewoWidok;
    private JPanel panelUML;
    private JFileChooser fc;
    private JXTaskPane klasa;
    private Graph graph;
    private VisualizationViewer vv;
    private Layout layout;
    private GraphCollapser collapser;
    private String p1 = "Package Java-analyzer";
    private Vector paczki;
    private Vector klasy;
    private Vector metody;
    private JScrollPane scrollPanelUML;
    private JarFile dekompilator;

    private String sciezka;
    
    private Integer i, j, k, l;

    private uml.Main pliki;
    //private Flow flow;
    private Flow f;

    /** Creates new form javaanalyzerUI */
    public javaanalyzerUI() {

        setTitle("Java analyzer v. 1.0");

        String args[] = new String[2];
	args[0] = "DataFlow.java";
        args[1] = "Data.java";
                    
        graph = new SparseGraph();
        
        

        
        //Tworzenie Grafu przedstawiajacego Package
     
        layout = new FRLayout(graph);

        Dimension preferredSize = new Dimension(500,300);
        final VisualizationModel visualizationModel =
            new DefaultVisualizationModel(layout, preferredSize);
        vv =  new VisualizationViewer(visualizationModel, preferredSize);

        //Ustawienie wyglądu i opisu wierzcholkow

        vv.getRenderContext().setVertexShapeTransformer(new ClusterVertexShapeFunction());
        vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());

        ///
        
        vv.setBackground(Color.white);

        final DefaultModalGraphMouse graphMouse = new DefaultModalGraphMouse();
        vv.setGraphMouse(graphMouse);

        Container content = getContentPane();
        GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
        //content.add(gzsp);

        JComboBox modeBox = graphMouse.getModeComboBox();
        modeBox.addItemListener(graphMouse.getModeListener());
        graphMouse.setMode(ModalGraphMouse.Mode.PICKING);
        
       
        JButton collapse = new JButton("Rozszerz/zawęź");
        collapse.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                Vector picked = new Vector(vv.getPickedVertexState().getPicked());
                Vector wszystkieW = new Vector(layout.getGraph().getVertices());
               
                for(i=0; i<picked.size(); i++){

                     if(klasy.contains(picked.elementAt(i)) && graph.containsVertex(picked.elementAt(i))){
                         
                         mClass element = (mClass)(picked.elementAt(i));
                                                  
                         if(graph.outDegree(element)==1){
                            for(j=0; j<element.V_method.size(); j++){
                                graph.addVertex(element.V_method.elementAt(j));
                                graph.addEdge(graph.getEdgeCount(), element, element.V_method.elementAt(j));
                            }
                        }else{
                            for(j=0; j<element.V_method.size(); j++){
                                graph.removeVertex(element.V_method.elementAt(j));
                            }
                        }

                     }

                    if(paczki.contains(picked.elementAt(i)) && graph.containsVertex(picked.elementAt(i))){

                        mPackage element = (mPackage)(picked.elementAt(i));                       

                        if(graph.outDegree(element)==0){
                            for(j=0; j<element.V_class.size(); j++){
                                graph.addVertex(element.V_class.elementAt(j));
                                graph.addEdge(graph.getEdgeCount(), element, element.V_class.elementAt(j));
                            }
                        }else{
                            for(j=0; j<element.V_class.size(); j++){

                                for(k=0; k<element.V_class.elementAt(j).V_method.size(); k++){
                                     graph.removeVertex(element.V_class.elementAt(j).V_method.elementAt(k));
                                }

                                graph.removeVertex(element.V_class.elementAt(j));
                            }
                        }

                    }
                }


                layout.initialize();

        		Relaxer relaxer = new VisRunner((IterativeContext)layout);
        		relaxer.stop();
        		relaxer.prerelax();
        		StaticLayout<Number,Number> staticLayout =
        			new StaticLayout<Number,Number>(graph, layout);
				LayoutTransition<Number,Number> lt =
					new LayoutTransition<Number,Number>(vv, vv.getGraphLayout(),
							staticLayout);
				Animator animator = new Animator(lt);
				animator.start();
//				vv.getRenderContext().getMultiLayerTransformer().setToIdentity();
				vv.repaint();

                vv.getPickedVertexState().clear();
                vv.repaint();

            }});

                     
        //collapse.setText("Wykonaj");
        //getContentPane().add(collapse);
        //collapse.setBounds(0, 0, 190, 23);

        initComponents();
                        
        //panelZakladki.setTitleAt(0, "UML");
        //panelZakladki.setTitleAt(1, "Listing");

        fc = new JFileChooser();

        Color kolorTla = new Color(236,233,216);

        panelUML = new JPanel();
        panelUML.setSize(600, 800);
        panelUML.setLayout(new FlowLayout());
        panelUML.setBackground(Color.WHITE);


        scrollPanelUML = new JScrollPane();

        scrollPanelUML.setViewportBorder(new LineBorder(Color.BLUE));
        scrollPanelUML.getViewport().add(panelUML, null);

        scrollPanelUML.setLayout(new ScrollPaneLayout());
        scrollPanelUML.revalidate();
        scrollPanelUML.repaint();
        //scrollPanelUML.add(panelUML);

        //panelZakladki.remove(1);

        JPanel kontrolka = new JPanel();
        kontrolka.add(collapse, BorderLayout.WEST);
        kontrolka.add(modeBox, BorderLayout.WEST);

        gzsp.add(kontrolka, BorderLayout.SOUTH);

        panelZakladki.add(gzsp);
        //panelZakladki.setComponentAt(0, gzsp);
        panelZakladki.setTitleAt(0, "Graph");
        panelZakladki.add("UML", scrollPanelUML);
        przyciskTworzListing.setEnabled(false);

        
        JButton przyciskDoUML = new JButton("Wyświetl UML klas zawierających zaznaczone metody");
        przyciskDoUML.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                Vector picked = new Vector(vv.getPickedVertexState().getPicked());
                Vector nowyUML = new Vector();
                
                for(i=0; i<picked.size(); i++){

                    if(metody.contains(picked.elementAt(i)) && graph.containsVertex(picked.elementAt(i))){                       

                        if(!nowyUML.containsAll(graph.getPredecessors(picked.elementAt(i)))){
                            nowyUML.addAll(graph.getPredecessors(picked.elementAt(i)));
                        }
                    }
                }

                if(nowyUML.size()>0){
                    panelUML.removeAll();
                }

                vv.getPickedVertexState().clear();

                for(i=0; i<nowyUML.size(); i++){

                    mClass element = (mClass)(nowyUML.elementAt(i));

                        klasa = new JXTaskPane();
                        klasa.setVisible(true);
                        klasa.setTitle(element.toString());                        
                        klasa.setCollapsed(false);

                        //String[] nazwyZmiennych = {"x: integer", "tmp: string", "val: float"};
                        //JList listaZmienne = new JList();

                        Vector nazwyZmiennych = new Vector();

                        for(j=0; j<element.V_types.size(); j++){                            

                            nazwyZmiennych.add(element.V_types.elementAt(j).toString());
                        }

                        JList listaZmienne = new JList(nazwyZmiennych);
                        listaZmienne.setBackground(Color.WHITE);
                        klasa.setBackground(Color.WHITE);

                        klasa.add(listaZmienne);

                        JSeparator poZmiennych = new JSeparator();
                        klasa.add(poZmiennych);

                        Vector nazwyMetod = new Vector();

                        for(j=0; j<element.V_method.size(); j++){

                            nazwyMetod.add(element.V_method.elementAt(j));
                        }

                        JList listaMetody = new JList(nazwyMetod);

                        ListSelectionListener listSelectionListener = new ListSelectionListener() {
                          public void valueChanged(ListSelectionEvent listSelectionEvent) {
                            
                            boolean adjust = listSelectionEvent.getValueIsAdjusting();                            
                            if (!adjust) {
                              JList list = (JList) listSelectionEvent.getSource();
                              int selections[] = list.getSelectedIndices();
                              Object selectionValues[] = list.getSelectedValues();
                              /*for (int i = 0, n = selections.length; i < n; i++) {
                                System.out.println(selectionValues[i]);
                              }*/

                              mMethod metoda = (mMethod) selectionValues[0];

                              System.out.println(selectionValues[0]+"; metoda: "+metoda+" klasa: "+metoda.clas+" paczka: "+metoda.clas.pack);
                              listaArgumenty.setListData(metoda.V_arguments);
                              listaArgumenty.setEnabled(true);

                            }
                          }
                        };
                        listaMetody.addListSelectionListener(listSelectionListener);




                        listaMetody.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

                        klasa.add(listaMetody);

                        panelUML.add(klasa);


                }

                if(nowyUML.size()>0){
                    panelZakladki.setSelectedComponent(scrollPanelUML);
                }

            }});

            kontrolka.add(przyciskDoUML, BorderLayout.EAST);
            
            

               
    }


    class ClusterVertexShapeFunction<V> extends EllipseVertexShapeTransformer<V> {

        ClusterVertexShapeFunction() {            
            setSizeTransformer(new ClusterVertexSizeFunction<V>(20));
        }
        @Override
        public Shape transform(V v) {
            
            //if(v instanceof Graph) {
            
            if(paczki.contains(v)){
                return factory.getRegularPolygon(v, 8);                
                //return factory.getRegularStar(v,5);


            }else if(metody.contains(v)){
                // return factory.getRegularPolygon(v, 8);
                return factory.getRegularStar(v,5);
            }


                /*
                int size = ((Graph)v).getVertexCount();
                if (size < 8) {
                    int sides = Math.max(size, 3);
                    return factory.getRegularPolygon(v, sides);
                }
                else {
                    return factory.getRegularStar(v, size);
                }*/
           //}
            return super.transform(v);
        }
    }




    class ClusterVertexSizeFunction<V> implements Transformer<V,Integer> {
    	int size;
        public ClusterVertexSizeFunction(Integer size) {
            
            this.size = size;
        }

        public Integer transform(V v) {
            
            if(paczki.contains(v)){
                return 50;
            }else if(klasy.contains(v)){
                return 25;
            }else{

            return 15;
            }
        }
    }




    class ActionJList extends MouseAdapter{
      protected JList list;

      public ActionJList(JList l){
       list = l;
       }

        public void mouseClicked(MouseEvent e){
            //if(e.getClickCount() == 2){
                int index = list.locationToIndex(e.getPoint());
                ListModel dlm = list.getModel();
                Object item = dlm.getElementAt(index);;
                list.ensureIndexIsVisible(index);
                System.out.println("Double clicked on " + item);

                przyciskTworzListing.setEnabled(false);
                listaArgumenty.setEnabled(true);

                if(index==0 || index==1){
                    
                    Vector data = new Vector();
                    data.addElement("str: String");
                    listaArgumenty.setListData(data);

                }else if(index==2){

                    Vector data = new Vector();
                    data.addElement("id: Integer");
                    data.addElement("data: String");
                    listaArgumenty.setListData(data);

                }



        }
            //}
    }


    private void listaMetodyValueChanged(javax.swing.event.ListSelectionEvent evt) {

        System.out.println(evt.getFirstIndex());
    }


    public void actionPerformed(ActionEvent e) {

    }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        panelZakladki = new javax.swing.JTabbedPane();
        przyciskWczytaj = new javax.swing.JButton();
        tekstSciezka = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        przyciskTworzListing = new javax.swing.JButton();
        przyciskZamknij = new javax.swing.JButton();
        panelKlasy = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        listaArgumenty = new javax.swing.JList();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(900, 520));
        setResizable(false);
        getContentPane().setLayout(null);

        panelZakladki.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                panelZakladkiStateChanged(evt);
            }
        });
        getContentPane().add(panelZakladki);
        panelZakladki.setBounds(230, 10, 650, 460);

        przyciskWczytaj.setText("Wczytaj plik");
        przyciskWczytaj.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                przyciskWczytajActionPerformed(evt);
            }
        });
        getContentPane().add(przyciskWczytaj);
        przyciskWczytaj.setBounds(20, 90, 190, 23);

        tekstSciezka.setText("Ścieżka");
        tekstSciezka.setEnabled(false);
        getContentPane().add(tekstSciezka);
        tekstSciezka.setBounds(30, 50, 180, 20);

        jLabel1.setText("Plik:");
        jLabel1.setMaximumSize(new java.awt.Dimension(50, 14));
        jLabel1.setMinimumSize(new java.awt.Dimension(50, 14));
        jLabel1.setPreferredSize(new java.awt.Dimension(50, 14));
        getContentPane().add(jLabel1);
        jLabel1.setBounds(30, 20, 50, 14);

        jLabel2.setText("Java-analyzer v. 1.0");
        jLabel2.setMaximumSize(new java.awt.Dimension(150, 14));
        jLabel2.setMinimumSize(new java.awt.Dimension(150, 14));
        jLabel2.setPreferredSize(new java.awt.Dimension(150, 14));
        getContentPane().add(jLabel2);
        jLabel2.setBounds(40, 410, 150, 14);

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Listing"));
        jPanel2.setPreferredSize(new java.awt.Dimension(200, 190));
        jPanel2.setLayout(null);

        przyciskTworzListing.setText("Stwórz Listing");
        przyciskTworzListing.setEnabled(false);
        przyciskTworzListing.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                przyciskTworzListingMouseReleased(evt);
            }
        });
        jPanel2.add(przyciskTworzListing);
        przyciskTworzListing.setBounds(20, 20, 150, 23);

        przyciskZamknij.setText("Zamknij ten listing");
        przyciskZamknij.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                przyciskZamknijMouseReleased(evt);
            }
        });
        przyciskZamknij.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                przyciskZamknijActionPerformed(evt);
            }
        });
        jPanel2.add(przyciskZamknij);
        przyciskZamknij.setBounds(20, 50, 150, 23);

        getContentPane().add(jPanel2);
        jPanel2.setBounds(10, 300, 200, 90);

        panelKlasy.setBorder(javax.swing.BorderFactory.createTitledBorder("Właściwości klasy"));
        panelKlasy.setLayout(null);

        jLabel3.setText("Argumenty wybranej funkcji:");
        panelKlasy.add(jLabel3);
        jLabel3.setBounds(10, 20, 180, 14);

        listaArgumenty.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        listaArgumenty.setEnabled(false);
        listaArgumenty.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                listaArgumentyMouseReleased(evt);
            }
        });
        listaArgumenty.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listaArgumentyValueChanged(evt);
            }
        });
        jScrollPane2.setViewportView(listaArgumenty);

        panelKlasy.add(jScrollPane2);
        jScrollPane2.setBounds(10, 40, 180, 110);

        getContentPane().add(panelKlasy);
        panelKlasy.setBounds(10, 130, 200, 160);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void przyciskWczytajActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_przyciskWczytajActionPerformed

         
         fc.setVisible(true);
         int returnVal = fc.showOpenDialog(javaanalyzerUI.this);

         if(returnVal == JFileChooser.APPROVE_OPTION) {
            System.out.println("Wybrano plik: " +
            fc.getSelectedFile().getName());
            
            sciezka = fc.getSelectedFile().getAbsolutePath();
            tekstSciezka.setText(sciezka);

            if(!sciezka.toLowerCase().endsWith(".java") && !sciezka.toLowerCase().endsWith(".jar")){
                System.out.println("Niewlasciwy plik");
                JOptionPane.showMessageDialog(null, "Niewłaściwy plik");
                return;
            }else{
                Object[] wierzch = graph.getVertices().toArray();
                 for(int i=0; i<wierzch.length; i++){
                    graph.removeVertex(wierzch[i]);
                }
                
                paczki = new Vector();
                klasy = new Vector();
                metody = new Vector();

                vv.repaint();
            }


            if(sciezka.toLowerCase().endsWith(".jar")){
                dekompilator = new JarFile(sciezka);
                dekompilator.clearDirectory("decompiled_classes");
                dekompilator.decompile("decompiled_classes");
                try {

                    Vector sciezki = dekompilator.getFileList(sciezka);
                    System.out.println(" *************************************************");
                     Vector sciezkai = dekompilator.getFileList("C:\\Users\\Robert\\Desktop\\trunk");
                    System.out.println(sciezkai  +  " *************************************************");
                    String[] args = new String[sciezki.size()];
                    
                    System.out.println(sciezki);                
                    
                    for(int i=0; i< args.length; i++){
                        args[i] = sciezki.elementAt(i).toString();
                        System.out.println("sciezka: "+args[i]);
                    }

                    /*
                    Collection wierzch = graph.getVertices();

                    for (Object w : wierzch) {
                        graph.removeVertex(w);
                    }*/
                   
                    pliki = new uml.Main(args);                    

                    System.out.println("Ilosc package: "+pliki.V_package.size());

                    for(i=0; i<pliki.V_package.size(); i++){

                        System.out.println("Nazwa package: "+pliki.V_package.elementAt(i).name);
                        graph.addVertex(pliki.V_package.elementAt(i));
                        paczki.add(pliki.V_package.elementAt(i));

                        for(j=0; j<pliki.V_package.elementAt(i).V_class.size(); j++){
                            klasy.add(pliki.V_package.elementAt(i).V_class.elementAt(j));
                            for(k=0; k<(pliki.V_package.elementAt(i).V_class.elementAt(j).V_method.size()); k++) {
                                metody.add(pliki.V_package.elementAt(i).V_class.elementAt(j).V_method.elementAt(k));
                            }
                        }
                    }

                    vv.repaint();
                    dekompilator.clearDirectory("decompiled_classes");
                    
		} catch (InterruptedException e) {
			e.printStackTrace();
                        JOptionPane.showMessageDialog(null, "Dekompilacja pliku JAR nie powiodła się");

		}

            }else if(sciezka.toLowerCase().endsWith(".java")){

                Collection wierzch = graph.getVertices();

                for (Object w : wierzch) {
                    graph.removeVertex(w);
                }

                String[] args = new String[1];
                args[0] = sciezka;
                pliki = new uml.Main(args);               

                System.out.println("Ilosc package: "+pliki.V_package.size());

                for(i=0; i<pliki.V_package.size(); i++){

                    System.out.println("Nazwa package: "+pliki.V_package.elementAt(i).name);
                    graph.addVertex(pliki.V_package.elementAt(i));
                    paczki.add(pliki.V_package.elementAt(i));

                    for(j=0; j<pliki.V_package.elementAt(i).V_class.size(); j++){
                        klasy.add(pliki.V_package.elementAt(i).V_class.elementAt(j));
                        for(k=0; k<(pliki.V_package.elementAt(i).V_class.elementAt(j).V_method.size()); k++) {
                            metody.add(pliki.V_package.elementAt(i).V_class.elementAt(j).V_method.elementAt(k));
                        }
                    }
                }

                vv.repaint();

            }           


        }



    }//GEN-LAST:event_przyciskWczytajActionPerformed

    private void listaArgumentyValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_listaArgumentyValueChanged

        przyciskTworzListing.setEnabled(true);
    }//GEN-LAST:event_listaArgumentyValueChanged

    private void listaArgumentyMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_listaArgumentyMouseReleased
//        int index = list.locationToIndex(e.getPoint());
//        ListModel dlm = this.getModel();
//        Object item = dlm.getElementAt(index);;
//        list.ensureIndexIsVisible(index);
//        System.out.println("Double clicked on " + item);
    }//GEN-LAST:event_listaArgumentyMouseReleased

    private void przyciskTworzListingMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_przyciskTworzListingMouseReleased

        if(przyciskTworzListing.isEnabled()){

            JPanel nowyPrzeplyw = new JPanel();

            panelZakladki.add(nowyPrzeplyw);
            panelZakladki.setTitleAt(panelZakladki.getComponentCount()-1, "Przepływ "+(panelZakladki.getComponentCount()-2));
            panelZakladki.setSelectedIndex(panelZakladki.getComponentCount()-1);
            
            mArguments arg = (mArguments) listaArgumenty.getSelectedValue();

            Flow f;
            try {
                //System.out.println(sciezka);
                Vector<String> fileList;
                try{
                     fileList = dekompilator.getFileList(sciezka);
                }
                catch(NullPointerException e){
                    fileList = new Vector<String>();
                    fileList.add(sciezka);
                }

                f = new Flow(fileList, arg.metod.clas.pack.name, arg.metod.clas.name, arg.metod.name.substring(0,arg.metod.name.length()-2), arg.name);
                nowyPrzeplyw.setBackground(Color.WHITE);
                nowyPrzeplyw.add(f.GetTree());
            } catch (InterruptedException ex) {
                Logger.getLogger(javaanalyzerUI.class.getName()).log(Level.SEVERE, null, ex);
            }



        }
    }//GEN-LAST:event_przyciskTworzListingMouseReleased

    private void przyciskZamknijMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_przyciskZamknijMouseReleased
        // TODO add your handling code here:

        if(panelZakladki.getTabCount()>2){

            panelZakladki.remove(panelZakladki.getSelectedIndex());
        }

        


    }//GEN-LAST:event_przyciskZamknijMouseReleased

    private void panelZakladkiStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_panelZakladkiStateChanged
        // TODO add your handling code here:

        if(panelZakladki.getSelectedIndex()>1){
            przyciskZamknij.setEnabled(true);
        }else{
            przyciskZamknij.setEnabled(false);
        }

    }//GEN-LAST:event_panelZakladkiStateChanged

    private void przyciskZamknijActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_przyciskZamknijActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_przyciskZamknijActionPerformed

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {    
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {                
                new javaanalyzerUI().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JList listaArgumenty;
    private javax.swing.JPanel panelKlasy;
    private javax.swing.JTabbedPane panelZakladki;
    private javax.swing.JButton przyciskTworzListing;
    private javax.swing.JButton przyciskWczytaj;
    private javax.swing.JButton przyciskZamknij;
    private javax.swing.JTextField tekstSciezka;
    // End of variables declaration//GEN-END:variables

}
